<?php


namespace app\system\service;

class AgentLogService
{
	public static function get_money_list($options)
	{
		$where = [];
		if (isset($options["agent_id"]) && $options["agent_id"] != "") {
			$where[] = ["u.id", "=", $options["agent_id"]];
		}
		if (isset($options["agent_name"]) && $options["agent_name"] != "") {
			$where[] = ["u.name", "like", "%" . $options["agent_name"] . "%"];
		}
		if (!empty($options["time_scope"]) && count($options["time_scope"]) > 1) {
			$time_scope = $options["time_scope"];
			$where[] = ["log.time", ">=", strtotime($time_scope[0])];
			$where[] = ["log.time", "<", strtotime($time_scope[1])];
		}
		$count = \think\Db::name("app_agent_money_log")->where($where)->alias("log")->join("app_agent u", "log.uid = u.id")->count();
		$pages = ceil($count / $options["limit"]);
		$list = \think\Db::name("app_agent_money_log")->where($where)->alias("log")->join("app_agent u", "log.uid = u.id")->order("log.id", "desc")->page($options["page"], $options["limit"])->group("log.id")->field("log.*")->select();
		$data = [];
		foreach ($list as $item) {
			$item["agent_info"] = \think\Db::name("app_agent")->where(["id" => $item["uid"]])->find();
			$data[] = $item;
		}
		return ["code" => \app\system\model\Code::success, "data" => $data, "count" => $count, "pages" => $pages];
	}
}